import java.util.*;
/*******************************************************************************
 * Used to implement a model Von Neumann instruction stack is for
 * instruction processing.  Fairly straighforward data structure.
 ******************************************************************************/
public class Buffer<T>{
	protected ArrayList<T> line;
	/***************************************************************************
	 * Construct a new one with initially no elements.
	 * note: parameter brackets do not appear in the constructor signature
	 ***************************************************************************/
	public Buffer(){
		line = new ArrayList<T>();
	}/*</Buffer>*/
	/***************************************************************************
	 * New buffer.
	 * @param n initial size of ArrayList the buffer wraps.
	 * @return the new one
	 **************************************************************************/
	public Buffer(int n){
		line = new ArrayList<T>(n);
	}/*</Buffer>*/
	/***************************************************************************
	 * Returns the thing in the queue with equal address value
	 * @return The thing,  null if not found
	 **************************************************************************/
	public T get(T t){
		for(int i=0;i<line.size();i++)
			if(line.get(i)==t)
				return line.get(i);
		return null;
	}/*</get>*/
	/***************************************************************************
	 * Get the first element from the top of the stack, and remove it
	 * @return The thing, null if no element exists.
	 **************************************************************************/
	public T deque(){
		if(line.isEmpty())
			return null;
		return line.remove(0);
	}/*</deque>*/
	/***************************************************************************
	 * Adds the new element to end of buffer.
	 * @return whether concatenation successful
	 **************************************************************************/
	public boolean queue(T t){
			line.add(t);
			return true;
	}/*</queue>*/
	/***************************************************************************
	 * Returns true if underlying ArrayList.length()==0
	 * @return Whether the set is empty
	 **************************************************************************/
	 boolean isEmpty(){
		return line.isEmpty();
	}/*</isEmpty>*/
	/***************************************************************************
	 * Number of elements being stored.
	 * @return Length of queue
	 **************************************************************************/
	public int size(){
		return line.size();
	}/*</size>*/
}/*</Buffer>*/
